﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.SessionState;
using Discuz.Toolkit;

namespace Icst.Leaflike
{
    public static class SessionExtension
    {
        public static UserData UserData(this HttpSessionState session)
        {
            UserData data = session["userdata"] as UserData;
            if (data == null)
            {
                data = new UserData();
                session["userdata"] = data;
            }
            return data;
        }
    }

    public class UserData
    {
        internal UserData() 
        { 
            Version = Version.Public;
        }

        public Version Version { get; set; }
        public User User { get; set; }

        public bool IsUserLogon { get { return User != null; } }
        public bool IsUserAdmin { get { return IsUserLogon && User.Adminid.HasValue; } }
        public string UserName { get { return User.UserName; } }
        public long UserId { get { return User.UId; } }
    }
}
